#include <bits/stdc++.h>
using namespace std;
int n;
int mp[55][55];
int f[55][55];
int dep[55];
int _log2[55];
void DFS(int i, int d)
{
	dep[i] = d;
	for (int j = 1; j <= n; j++)
		if (mp[i][j] == 1)
			DFS(j, d + 1); //处理深度
}
int LCA(int x, int y)
{
	if (dep[x] < dep[y]) //默认x的深度大
		swap(x, y);
	int d = dep[x] - dep[y];
	for (int i = _log2[d]; i >= 0; i--)
		if (dep[f[x][i]] >= dep[y]) //调整到统一的深度
			x = f[x][i];
	if (x == y) //如果两点相同,显然LCA就是x或y
		return x;
	for (int i = _log2[n]; i >= 0; i--)
		if (f[x][i] != f[y][i]) //不相同时,看x与y的第i级祖先,相同的话,说明LCA在它下面,故不换,反之,换s
		{
			x = f[x][i];
			y = f[y][i];
		}
	return f[x][0]; //答案
}
int main()
{
	int x, y;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		mp[u][v] = 1;
		mp[v][u] = 1;
	}
	DFS(1, 1);
	_log2[0] = -1;
	for (int i = 1; i <= n; i++)
		_log2[i] = _log2[i / 2] + 1; //预处理log2
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= _log2[n]; j++)
			f[i][j] = f[f[i - 1][j - 1]][j - 1];
	scanf("%d %d", &x, &y);
	LCA(x, y);
	return 0;
}